package cn.org.timespace.easyframe.util.sqlserver;

import java.sql.Connection;
import java.sql.DriverManager;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

public class ConnectionManager {
	
	public static Connection getConnection() throws Exception{
		DbData dd=ConfigManager.parse("../Db.xml");
		Connection conn=null;
		if(dd.getUse().equals("DATA_SOURCE")){
			Context ctx=new InitialContext();
			DataSource ds=(DataSource)ctx.lookup(dd.getDataSource());
			conn=ds.getConnection();
		}else if(dd.getUse().equals("jdbc")){
			Class.forName(dd.getJdbcDriver());
			conn=DriverManager.getConnection(dd.getUrl(),dd.getUser(),dd.getPassword());
		}else {
			Exception e=new Exception("");
		}
		return conn;
	}
}
